package com.air.service.impl;

import com.air.dao.FlightMapper;
import com.air.entity.Flight;
import com.air.service.FlightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class FlightServiceImpl implements FlightService {

    @Autowired
    FlightMapper flightMapper;

    @Override
    public List<Flight> selecFlight(String takeoff, String landing, String firstdate) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            String a = firstdate + " 00:00:00";
            Date firstDate= sdf.parse(a);

            String b = firstdate + " 23:59:59";
            Date lastDate = sdf.parse(b);
            System.out.println("查询航班信息"+takeoff+" "+landing+" "+firstDate+" "+lastDate);
            return flightMapper.selecFlight(takeoff, landing, firstDate,lastDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return null;
    }

    @Override
    public Flight selecFlightById(String id) {
        return flightMapper.selecFlightById(id);
    }
}
